/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ourpkr.model.joueur;

import java.beans.*;
import java.util.Vector;
import ourpkr.OurPkrApp;
import ourpkr.model.*;

/**
 *
 * @author niboucha
 */
public abstract class Joueur {
    protected int fortune = 1000;
    protected EnsembleCartes main;
    protected String nom;
    protected int miseCourante = 0;
    protected int number;
    protected boolean alwaysInTour = false;
    protected boolean loose = false;
    
    protected boolean playing = false;
    private int whatToDo = 0;

    protected int getWhatToDo() {
        return whatToDo;
    }

    protected void setWhatToDo(int whatToDo) {
        int old = this.whatToDo;
        this.whatToDo = whatToDo;
        pcs.firePropertyChange("whatToDo",null,this.whatToDo);
    }

    public boolean isDealer() {
        return dealer;
    }

    public void setDealer(boolean dealer) {
        boolean old = this.dealer;
        this.dealer = dealer;
        pcs.firePropertyChange("dealer",old,this.dealer);
    }

    public boolean isLoose() {
        return loose;
    }

    public void setLoose(boolean loose) {
        boolean old = this.loose;
        this.loose = loose;
        pcs.firePropertyChange("loose",old,this.loose);
    }

    public boolean isPlaying() {
        return playing;
    }

    public void setPlaying(boolean playing) {
        boolean old = this.playing;
        this.playing = playing;
        pcs.firePropertyChange("playing",old,this.playing);
    }
    protected boolean dealer = false;

    public PropertyChangeSupport pcs;
    
    public boolean isAlwaysInTour() {
        return alwaysInTour;
    }

    public void setAlwaysInTour(boolean alwaysInTour) {
        boolean old = this.alwaysInTour;
        this.alwaysInTour = alwaysInTour;
        pcs.firePropertyChange("alwaysInTour",old,alwaysInTour);
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }
    
    public int miseMiniTour(){
        Vector<Joueur> listeJoueurs = new Vector<Joueur>();
        for(Joueur tmp : OurPkrApp.getApplication().getPc().getJoueurs()){
            if(tmp.isAlwaysInTour()) listeJoueurs.add(tmp);
        }
        int res = 0;
        if( listeJoueurs.size() > 0 )
        {           
            for(Joueur j : listeJoueurs)
            {
                if( j.getMiseCourante() > res ) res = j.getMiseCourante();
            }
            
        }
        return res;
    }
 
    public void addToFortune(int fortune) {
        int oldf = this.fortune;
        this.fortune += fortune;
        pcs.firePropertyChange("fortune",oldf,this.fortune);
    }

    public void setMain(EnsembleCartes main) {
        this.main = main;
        pcs.firePropertyChange("main",null,this.main);
    }

    public void setMiseCourante(int miseCourante) {
        int oldf = fortune;
        fortune -= miseCourante - this.miseCourante;
        int oldMc = this.miseCourante;
        this.miseCourante = miseCourante;        
        pcs.firePropertyChange("fortune",oldf,fortune);
        pcs.firePropertyChange("miseCourante",oldMc,this.miseCourante);
    }
    
    public void resetMiseCourante(){
        int old = miseCourante;
        miseCourante = 0;
        pcs.firePropertyChange("miseCourante",old,miseCourante);
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public int getFortune() {
        return fortune;
    }

    public EnsembleCartes getMain() {
        return main;
    }

    public int getMiseCourante() {
        return miseCourante;
    }

    public String getNom() {
        return nom;
    }
        
    public String toString(){
        return nom;
    }
    
    public abstract int joue();
    
    protected void message(String msg){
        System.out.println(msg);
    }
    
}
